package com.aaa.web.controller.repaircontroller;

import com.aaa.entity.AppUserinfo;
import com.aaa.entity.BackEmployeeinfo;
import com.aaa.entity.repair.BackEntrepot;
import com.aaa.entity.repair.BackCarRepair;
import com.aaa.web.commons.EmpQuery;
import com.aaa.web.commons.Result;
import com.aaa.web.service.irepairservice.IRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
/**
* @program:
* @description:维修信息
* @author:lianghuige
* @create:
**/
@Controller
@RequestMapping("/repair")
public class RepairController {


    @Autowired
    private IRepairService repairService;

    /**
     * 跳转至维修管理页面
     * @return
     */
    @RequestMapping("/getRepairInfo")
    public String getRepairPage() {
        return "views/webhtml/repair/toRepair";
    }

    /**
     * 查询维修信息  并返回至前台
     * @return
     */
    @RequestMapping("/findRepairInfo")
    @ResponseBody
    public Map findRepairInfo(EmpQuery query, BackCarRepair backCarRepair) {
        Map m=repairService.findRepairInfo(query, backCarRepair);
        return m;
    }

    /**
     * 根据repairid查询该维修单的详情
     * @param repairid
     * @return
     */
    @RequestMapping("/findRepairInfoById")
    @ResponseBody
    public Map findRepairInfoById(String repairid){

        return repairService.findRepairInfoById(repairid);
    }
    /**
     * 根据repairid删除对应的数据
     * @param repairid
     * @return
     */
    @RequestMapping("/delRepairInfoById")
    @ResponseBody
    public Result delRepairInfoById(String repairid){

        return repairService.delRepairInfoById(repairid);
    }
    /**
     * 添加维修单的弹框内的失焦事件
     * 根据---------名字---------获取车主信息及车辆信息
     *
     */
    @RequestMapping("/findCustomerInfo")
    @ResponseBody
    public Map findCustomerInfoByName(String name){
       return  repairService.findCustomerInfoByName(name);
    }
    /**
     * 添加维修单的弹框内的失焦事件
     * 根据---------手机号----------获取车主信息及车辆信息
     *
     */
    @RequestMapping("/findCustomerInfoByTel")
    @ResponseBody
    public Map findCustomerInfoByTel(String tel){

        return  repairService.findCustomerInfoByTel(tel);
    }
    /**
     * 添加维修单的弹框内的失焦事件
     * 根据车---------型号----------获取车主信息及车辆信息
     *
     */
    @RequestMapping("/findCustomerInfoByCarcode")
    @ResponseBody
    public Map findCustomerInfoByCarcode(String carcode){

        return  repairService.findCustomerInfoByCarcode(carcode);
    }

    /**
     * 添加维修单的维修员工---select自动从数据库获取
     *
     *
     */
    @RequestMapping("/listEmp")
    @ResponseBody
    public List<BackEmployeeinfo> listEmp(){

        return  repairService.listEmp();
    }
    /**
     * 添加维修单的仓库零件----checkbox自动从数据库获取零件信息
     *
     *
     */
    @RequestMapping("/listComponent")
    @ResponseBody
    public List<Map> listComponent(){

        return  repairService.listComponent();
    }
    /**
     * 维修单提交
     */
    @RequestMapping("/addRepairInfo")
    @ResponseBody
    public Result addRepairInfo(BackCarRepair backCarRepair, @RequestParam(defaultValue="0",required=false)double reprice, @RequestParam(defaultValue="0",required=false)double coprice, double total, @RequestParam(value = "arr[]",required = false) String[] arr){


        return repairService.addRepairInfo(backCarRepair,reprice,coprice,total,arr);
    }
}

